package de.lns.entities.ai;

import de.lns.entities.turrets.Bullet;
import de.lns.tick.UpdateThread;
/**
 * 
 * @author Frederick Hastedt
 *
 */
public class StraightBulletai extends Bulletai {
	/**
	 * hypotenuseLength: the length of the distance between the bullet and the mob's original position
	 * bullet: Bullet object
	 * mobX: the mob's original X coordinate
	 * mobY: the mob's original Y coordinate
	 */
	private double hypotenuseLength;
	private Bullet bullet;
	private double mobX;
	private double mobY;
	private double travelDistance;
	private double xDiff;
	private double yDiff;

	/**
	 * 
	 * @param bullet: the bullet that's currently being moved
	 */
	public StraightBulletai(Bullet bullet) {
		this.bullet = bullet;
		mobX = bullet.getTarget().getPosX();
		mobY = bullet.getTarget().getPosY();
	}
	
	@Override
	public void move() {
		
		travelDistance = bullet.getSpeed()*UpdateThread.getDelta()/1000;
		
		while(travelDistance > 0){
			xDiff = mobX - bullet.getPosX();
			yDiff = mobY - bullet.getPosY();
			hypotenuseLength = Math.hypot(xDiff, yDiff);
			if(travelDistance >= hypotenuseLength){
				bullet.setPosX(mobX);
				bullet.setPosY(mobY);
				bullet.removeBullet();
				return;
				
			} else {
				//mob.setDirection(Math.asin(xDiff/hypotenuseLength));
				bullet.setPosX(bullet.getPosX() + ((xDiff/hypotenuseLength)*travelDistance));
				bullet.setPosY(bullet.getPosY() + ((yDiff/hypotenuseLength)*travelDistance));
				return;
			}
		}
	}
	
	/**
	 * method to move the bullet
	 */
//	public void move() {
//
//		hypotenuseLength = Math.hypot(
//				bullet.getTarget().getPosX() - bullet.getPosX(), bullet
//						.getTarget().getPosY() - bullet.getPosY());
//		bullet.setPosX(bullet.getPosX()
//				+ ((mobX - bullet.getPosX()) / (hypotenuseLength / bullet
//						.getSpeed())) * UpdateThread.getDelta() / 1000);
//		bullet.setPosY(bullet.getPosY()
//				+ ((mobY - bullet.getPosY()) / (hypotenuseLength / bullet
//						.getSpeed())) * UpdateThread.getDelta() / 1000);
//
//	}

}